package praktikumid.w09.p1;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

/**
 * Draw panel.
 * @author Ago
 *
 */
public class DrawPanel extends Canvas {

	/**
	 * Constructor.
	 */
	public DrawPanel() {
		setBackground(Color.WHITE);
	}
	
	/**
	 * Draws oval on the canvas.
	 * @param x x-coordinate
	 * @param y y-coordinate
	 */
	public void drawOval(int x, int y) {
		Graphics g = getGraphics();
		g.drawOval(x, y, 100, 120);
		// calling dispose() is preferred
		g.dispose();
	}
	
	/**
	 * Draws rectangle on the canvas.
	 * @param x x-coordinate
	 * @param y y-coordinate
	 * @param width width of the rectangle
	 * @param height height of the rectangle
	 */
	public void drawRectangle(int x, int y, int width, int height) {
		Graphics g = getGraphics();
		g.drawRect(x, y, width, height);
		g.dispose();
	}
	/**
	 * Draw line.
	 * @param x1 starting x-coordinate
	 * @param y1 starting x-coordinate
	 * @param x2 ending x-coordinate
	 * @param y2 ending y-coordinate
	 */
	public void drawLine(int x1, int y1, int x2, int y2) {
		Graphics g = getGraphics();
		g.setColor(Color.RED);
		g.drawLine(x1, y1, x2, y2);
		g.dispose();
	}
	
	@Override
	public void paint(Graphics g) {
		// called on resize, maximize/restore etc.
		// manually can be called by repaint();
		super.paint(g);
		g.setColor(Color.BLUE);
		g.drawLine(600, 0, 0, 600);
	}
}
